from __future__ import absolute_import, division

from gui.panda.base import *


class PandaDateBar(PandaUIElement):
    texture_name =_ ('UI Date Bar')
    
    day         = Attribute()
    day_suffix  = Attribute()
    month       = Attribute()
    year        = Attribute()
    year_suffix = Attribute()
    
    def setup_element(self):
        self.day         = self.add_child(Label('bar.date.day',         ( 33, 25), text_align = '>'))
        self.day_suffix  = self.add_child(Label('bar.date.day.suffix',  ( 34, 21), text_align = '<', font_size = 10))
        self.month       = self.add_child(Label('bar.date.month',       (125, 25), text_align = '|'))
        self.year        = self.add_child(Label('bar.date.year',        (244, 25), text_align = '>'))
        self.year_suffix = self.add_child(Label('bar.date.year.suffix', (246, 21), text_align = '<', font_size =  9))
    
    def on_update(self):
        self.day.text         = self.model.day
        self.day_suffix.text  = self.model.day_suffix
        self.month.text       = self.model.month
        self.year.text        = self.model.year
        self.year_suffix.text = self.model.year_suffix


class PandaCityNameBar(PandaUIElement):
    texture_name =_ ('UI City Name Bar')

    name        = Attribute()
    description = Attribute()
    
    def setup_element(self):
        self.name        = self.add_child(Label('bar.name.name', (104, 26), text_align = '|', font_size = 18))
        self.description = self.add_child(Label('bar.name.desc', (104, 50), text_align = '|', font_size = 11))
    
    def on_update(self):
        self.name.text        = self.model.name
        self.description.text = self.model.description


class PandaCityStateBar(PandaUIElement):
    texture_name =_ ('UI City State Bar')

    money      = Attribute()
    population = Attribute()
    surplus    = Attribute()
    
    icon_jobs    = Attribute()
    icon_workers = Attribute()
    
    def setup_element(self):
        self.money      = self.add_child(QuantityLabel('bar.state.money',   ( 93, 25)))
        self.population = self.add_child(QuantityLabel('bar.state.pop',     (179, 25)))
        self.surplus    = self.add_child(QuantityLabel('bar.state.surplus', (252, 25)))
        
        self.add_child(Icon('bar.state.icon.money', (104, 20), icon = 'Coin'))
        self.add_child(Icon('bar.state.icon.pop',   (190, 20), icon = 'Person'))
        
        self.icon_jobs    = self.add_child(Icon('bar.state.icon.surplus.jobs',    (262, 20), icon = 'Hammer'))
        self.icon_workers = self.add_child(Icon('bar.state.icon.surplus.workers', (262, 20), icon = 'Worker'))
    
    def on_update(self):
        self.money.text      = self.model.money
        self.population.text = self.model.population
        self.surplus.text    = self.model.surplus

        self.icon_jobs.visible    = self.model.surplus_is_jobs
        self.icon_workers.visible = self.model.surplus_is_workers
